package main

/*约瑟夫问题*/
import "fmt"

type Node struct {
	data int
	next *Node
}

func New(length int) *Node {
	var header, p, s *Node
	header = &Node{1, nil}
	p = header
	for i := 1; i < length; i++ {
		s = &Node{i + 1, nil}
		p.next = s
		p = s
	}
	p.next = header
	return header
}

func (header *Node) Ysf(size int) {
	var pre *Node
	for i := 1; header.next != header; {
		if i == size {
			fmt.Printf("%d -->", header.data)
			pre.next = header.next
			i = 0
		}
		pre = header
		i++
		header = header.next
	}
	fmt.Printf("%d -->", header.data)
}
func main() {
	link := New(41)

	link.Ysf(3)
}
